package com.gack.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gack.business.service.OpinionServiceInterface;
import com.gack.helper.common.AjaxJson;
import com.gack.helper.common.abstractobj.ApiController;

import io.swagger.annotations.ApiOperation;

/**
 * 
* @ClassName: OpinionController 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author (ZhangXinYu)  
* @date 2018年6月6日 下午3:46:08 
* @version V1.0
 */
@RestController
@RequestMapping(ApiController.OPINION_URL)
public class OpinionController {
	
	@Autowired
	private OpinionServiceInterface opinionService;
	
	@ApiOperation(value="查询意见反馈信息",notes="查询意见反馈信息")
	@PostMapping("getOpinions")
	public AjaxJson getOpinions(String startTime,String endTime,
			@RequestParam(value="source",defaultValue="app") String source,
			Integer currentPage,Integer pageSize){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setSuccess(true).setStatus(200).setData(opinionService.getOpinions(startTime, endTime,source,currentPage,pageSize));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(true).setStatus(500).setMsg("意见反馈查询操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="意见反馈回复",notes="意见反馈回复")
	@PostMapping("replyOpinion")
	public AjaxJson replyOpinion(String userid,String opinionId,String replytext){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setSuccess(true).setStatus(200).setData(opinionService.replyOpinion(userid,opinionId, replytext));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(500).setMsg("意见反馈回复操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="删除意见反馈",notes="删除意见反馈")
	@PostMapping("dealOpinion")
	public AjaxJson dealOpinion(String userid,String opinionId){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setSuccess(true).setStatus(200).setData(opinionService.dealOpinion(userid,opinionId));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(500).setMsg("意见反馈删除操作失败");
		}
		return ajaxJson;
	}
	
	@ApiOperation(value="查看意见反馈详情",notes="查看意见反馈详情")
	@PostMapping("getOpinionInfo")
	public AjaxJson getOpinionInfo(String id){
		AjaxJson ajaxJson = new AjaxJson();
		try{
			ajaxJson.setSuccess(true).setStatus(200).setData(opinionService.getOpinionInfo(id));
		}catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(500).setMsg("查询意见反馈详情操作失败");
		}
		return ajaxJson;
	}
	
}
